/*
 *  $TEAM_NAME Space Trader
 */
package views;

import models.Difficulty;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JTextField;
import net.miginfocom.swing.MigLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import javax.swing.DefaultComboBoxModel;
import javax.swing.event.ChangeListener;


/**
 * New Game Panel
 * @author twb
 * @version 1.0
 */
public class NewGamePanel extends JPanel {
	
	/**
	 * Field TEN.
	 * (value is 10)
	 */
	private static final int TEN = 10;
	
	/**
	 * Field FIVE.
	 * (value is 5)
	 */
	private static final int FIVE = 5;
	
	/**
	 * field
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * field
	 */
	private final JTextField nameField;
	
	/**
	 * field
	 */
	private final JLabel pointsLabel;
	
	/**
	 * field
	 */
	private final JLabel pilotLabel;
	
	/**
	 * field
	 */
	private final JLabel traderLabel;
	
	/**
	 * field
	 */
	private final JLabel fighterLabel;
	
	/**
	 * field
	 */
	private final JLabel engineerLabel;
	
	/**
	 * field
	 */
	private final JSlider fighterSlider;
	
	/**
	 * field
	 */
	private final JSlider pilotSlider;
	
	/**
	 * field
	 */
	private final JSlider traderSlider;
	
	/**
	 * field
	 */
	private final JSlider engineerSlider;

	/**
	 * field
	 */
	private final JButton btnBack;
    
	/**
	 * field
	 */
	private final JButton btnNext;
	
	/**
	 * field
	 */
	private final JComboBox difficultyBox;

	/**
	 * Create the 
	 */
	public NewGamePanel() {
		super.setLayout(new MigLayout("",
				"[74px,grow][294px]", 
"[28px][27px][16px][29px][29px][29px][29px][29px][][][][][][][][][grow]"));
		
		final JLabel lblName = new JLabel("Name");
		super.add(lblName, "cell 0 0,alignx right,aligny center");
		
		nameField = new JTextField();
		super.add(nameField, "cell 1 0,alignx center,aligny top");
		nameField.setColumns(TEN);
		
		final JLabel lblDifficulty = new JLabel("Difficulty");
		super.add(lblDifficulty, "cell 0 2,alignx right,aligny center");
		
		difficultyBox = new JComboBox();
		difficultyBox.setModel(new DefaultComboBoxModel(Difficulty.values()));
		super.add(difficultyBox, "cell 1 2,alignx center,aligny top");
		
		final JLabel lblSkillPoints = new JLabel("Skill Points:");
		super.add(lblSkillPoints, "cell 0 4,alignx right,aligny center");
		
		pointsLabel = new JLabel("16\n");
		super.add(pointsLabel, "cell 1 4,alignx center,aligny center");
		
		pilotLabel = new JLabel("Pilot (Skill: 1)");
		super.add(pilotLabel, "cell 0 7,alignx right,aligny center");
		
		pilotSlider = new JSlider(1, TEN, 1);
		pilotSlider.setPaintTicks(true);
		pilotSlider.setMajorTickSpacing(1);
		pilotSlider.setSnapToTicks(true);
		super.add(pilotSlider, "cell 1 7,growx,aligny top");
		
		traderLabel = new JLabel("Trader (Skill: 1)");
		super.add(traderLabel, "cell 0 8,alignx right,aligny center");
		
		traderSlider = new JSlider(1, TEN, 1);
		traderSlider.setPaintTicks(true);
        traderSlider.setSnapToTicks(true);
        traderSlider.setMajorTickSpacing(1);
        super.add(traderSlider, "cell 1 8,growx,aligny top");

        fighterLabel = new JLabel("Fighter (Skill: 1)");
        super.add(fighterLabel, "cell 0 10,alignx right,aligny center");

        fighterSlider = new JSlider(1, TEN, 1);
        fighterSlider.setPaintTicks(true);
        fighterSlider.setSnapToTicks(true);
        fighterSlider.setMajorTickSpacing(1);
        super.add(fighterSlider, "cell 1 10,growx,aligny top");

        engineerLabel = new JLabel("Engineer (Skill: 1)");
        super.add(engineerLabel, "cell 0 12,alignx right,aligny center");

        engineerSlider = new JSlider(1, TEN, 1);
        engineerSlider.setPaintTicks(true);
        engineerSlider.setSnapToTicks(true);
        engineerSlider.setMajorTickSpacing(1);
        super.add(engineerSlider, "cell 1 12,growx,aligny top");

        final JPanel panel = new JPanel();
        super.add(panel, "cell 0 16 2 1,grow");
        panel.setLayout(new FlowLayout(FlowLayout.CENTER, FIVE, FIVE));

        btnBack = new JButton("Back");
        panel.add(btnBack);

        btnNext = new JButton("Next");
        panel.add(btnNext);
    }

    /**
     * Method addActionListener.
     * @param listener ActionListener
     */
    public void addActionListener(ActionListener listener) {
        btnBack.addActionListener(listener);
        btnNext.addActionListener(listener);
    }

    /**
     * Method addChangeListener.
     * @param cl ChangeListener
     */
    public void addChangeListener(ChangeListener cl){
        pilotSlider.addChangeListener(cl);
        traderSlider.addChangeListener(cl);
        fighterSlider.addChangeListener(cl);
        engineerSlider.addChangeListener(cl);
    }

    /**
     * Method getName.
    
     * @return String */
    public String getName(){
        return nameField.getText();
    }

    /**
     * Method getFighter.
    
     * @return int */
    public int getFighter(){
        return fighterSlider.getValue();
    }

    /**
     * Method getPilot.
    
     * @return int */
    public int getPilot(){
        return pilotSlider.getValue();
    }

    /**
     * Method getTrader.
    
     * @return int */
    public int getTrader(){
        return traderSlider.getValue();
    }

    /**
     * Method getEngineer.
    
     * @return int */
    public int getEngineer(){
        return engineerSlider.getValue();
    }

    /**
     * Method setRemainingPoints.
     * @param points int
     */
    public void setRemainingPoints(int points){
        pointsLabel.setText(String.valueOf(points));
        
        if(points >= 0){
            pilotLabel.setText("Pilot (Skill: " + pilotSlider.getValue() + ")");
            traderLabel.setText("Trader (Skill: " + traderSlider.getValue() + ")");
            fighterLabel.setText("Fighter (Skill: " + fighterSlider.getValue() + ")");
            engineerLabel.setText("Engineer (Skill: " + engineerSlider.getValue() + ")");
        }
    }

    /**
     * Method getDifficulty.
    
     * @return Difficulty */
    public Difficulty getDifficulty(){
        return (Difficulty) difficultyBox.getSelectedItem();
    }
}
